package com.hmy.pig.controller;


import com.hmy.pig.domain.HmyPigTransfer;
import com.hmy.pig.service.PigTransferService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhl
 * @descript 描述
 * @date 2024/2/1 12:44
 */
@RestController
@RequestMapping("/pigTransfer")
public class HmyPigTransferController extends BaseController {
    @Autowired
    private PigTransferService pigTransferService;

    /**
     * 根据条件分页查询猪只转舍记录列表:  条件 猪只耳号、转出栏舍类型、转入栏舍类型、转舍时间
     *
     * @param pigCode 猪只耳号
     * @param topt 转出栏舍类型
     * @param tipt 转入栏舍类型
     * @param dateStart 转舍开始时间
     * @param dateEnd 转舍结束时间
     * @return 猪只转舍记录信息集合信息
     */
    @RequiresPermissions("hmy:pigTransfer:list")
    @GetMapping("/list")
    public TableDataInfo list(String pigCode ,
                              String topt,
                              String tipt,
                              String dateStart,
                              String dateEnd)
    {
        startPage();
        List<HmyPigTransfer> list = pigTransferService.selectPigTransfer(
                pigCode,
                topt,
                tipt,
                dateStart,
                dateEnd);
        return getDataTable(list);
    }
    /**
     * @param hmyPigTransfer
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @author ZHL
     * @date 2024/1/29 19:10
     * @description  新增猪只转舍记录
     */
    @RequiresPermissions("hmy:pigTransfer:add")
    @Log(title = "猪只转舍记录管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody HmyPigTransfer hmyPigTransfer)
    {
        return toAjax(pigTransferService.insertPigTransfer(hmyPigTransfer));
    }
    /**
     * 根据transferId获取单个转舍记录信息
     *
     * @param transferId
     * @return
     */
    @RequiresPermissions("hmy:pigTransfer:query")
    @GetMapping("getInfo/{transferId}")
    public AjaxResult selectPigTransferByTransferId(@PathVariable Long transferId) {
        return AjaxResult.success(pigTransferService.selectPigTransferByTransferId(transferId));
    }
    /**
     * 根据transferId修改转舍记录信息
     *
     * @param
     * @return
     */
    @PostMapping("update")
    @Log(title = "转舍记录管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("hmy:pigTransfer:update")
    public AjaxResult updatePigTransfer(@RequestBody HmyPigTransfer hmyPigTransfer) {
        return toAjax(pigTransferService.updatePigTransfer(hmyPigTransfer));

    }

    /**
     * 根据transferIds删除转舍记录信息
     *
     * @param transferIds
     * @return
     */
    @DeleteMapping("del/{transferIds}")
    @RequiresPermissions("hmy:pigTransfer:del")
    public AjaxResult delPigTransferByTransferIds(@PathVariable Long[] transferIds) {
        return toAjax(pigTransferService.deletePigTransferByTransferIds(transferIds));
    }
}
